//package cn.siat.gene.controller;
//
//import cn.hutool.core.date.DateTime;
//import cn.hutool.core.util.IdUtil;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import cn.siat.common.core.utils.StringUtils;
//import cn.siat.common.core.web.controller.BaseController;
//import cn.siat.common.core.web.domain.AjaxResult;
//import cn.siat.common.security.utils.SecurityUtils;
//import cn.siat.gene.domain.GRNADto;
//import cn.siat.gene.domain.GeneKnockOutDto;
//import cn.siat.gene.domain.PrimerPredictionFromGenBankDto;
//import cn.siat.gene.domain.Programme;
//import cn.siat.gene.service.IProgrammeService;
//import cn.siat.gene.util.CmdUtil;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.multipart.MultipartFile;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.*;
//import java.nio.charset.Charset;
//import java.util.Date;
//import java.util.Locale;
//
//@RestController
//@RequestMapping("/scheme")
//public class MolecularSchemeController extends BaseController {
//
//    @Autowired
//    private IProgrammeService iProgrammeService;
//
//
//
//    @Autowired
//    private IHostoryService historyService;
//
//    /**
//     * 从本地文件打开
//     */
//    @PostMapping("/cmd")
//    public String execCmdOrder(String cmdCommand) {
//
//        if (StringUtils.isEmpty(cmdCommand)){
//            throw new RuntimeException("需要执行的命令不可以为空");
//        }
//
//        /*if (***其他判断条件***){
//            throw new RuntimeException("不满足判断条件的原因");
//        }*/
//
//        //组装cmd 命令
//        String cmd= cmdCommand ;
//        BufferedReader br=null;
//        Process process=null;
//        //执行命令结果
//        StringBuilder result = null;
//        try {
//            //执行cmd命令
//            process=Runtime.getRuntime().exec(cmd);
//            //获取cmd命令的输出结果
//            br=new BufferedReader(new InputStreamReader(process.getInputStream(), Charset.forName("GBK")));
//            result= new StringBuilder();
//            String tmp;
//            //组装命令执行结束后返回值
//            while ((tmp= br.readLine())!=null){
//                result.append(tmp).append("\n");
//            }
//            process.waitFor();
//        } catch (InterruptedException | IOException e) {
//            log.error(e.getMessage());
//        }finally {
//            if (br!=null){
//                try {
//                    br.close();
//                } catch (IOException e) {
//                    log.error(e.getMessage());
//                }
//            }
//            if (process != null) {
//                process.destroy();
//            }
//            System.out.println("执行命令结束以后控制台返回结果为 ：" + result);
//        }
//        return result.toString();
//    }
////    public static void execCommandAndGetOutput() {
////        try {
////            Runtime runtime = Runtime.getRuntime();
////            Process process = runtime.exec("cmd.exe /c ipconfig");
////            // 输出结果，必须写在 waitFor 之前
////            String outStr = getStreamStr(process.getInputStream());
////            // 错误结果，必须写在 waitFor 之前
////            String errStr = getStreamStr(process.getErrorStream());
////            int exitValue = process.waitFor(); // 退出值 0 为正常，其他为异常
////            System.out.println("exitValue: " + exitValue);
////            System.out.println("outStr: " + outStr);
////            System.out.println("errStr: " + errStr);
////            process.destroy();
////        } catch (IOException | InterruptedException e) {
////            log.error(e.getMessage());
////        }
////    }
////
////    public static String getStreamStr(InputStream is) throws IOException {
////        BufferedReader br = new BufferedReader(new InputStreamReader(is, "GBK"));
////        StringBuilder sb = new StringBuilder();
////        String line;
////        while ((line = br.readLine()) != null) {
////            sb.append(line);
////            sb.append("\n");
////        }
////        br.close();
////        return sb.toString();
////    }
//
//    @PostMapping("/cmd-util")
//    public String cmdUtil(String cmdCommand) {
//
//        String s = CmdUtil.execCmdOrder(cmdCommand);
//        return s;
//    }
//
//    @Autowired
//    private GbffUtil gbffUtil;
//
//    @PostMapping("/gRNA")
//    public AjaxResult gRNA(GRNADto grnaDto) throws IOException, InterruptedException {
//        QueryWrapper programmeWrapper = new QueryWrapper();
//        programmeWrapper.eq("id", grnaDto.getProgrammeId());// 未打包标识
//        Programme programme =iProgrammeService.getOne(programmeWrapper);
//
//        QueryWrapper fileWrapper = new QueryWrapper();
//        fileWrapper.eq("id", programme.getLocalFileId()); // 未打包标识
//        cn.siat.gene.file.entity.File file =iFileService.getOne(fileWrapper);
//        String gbffPath = gbffUtil.getGbffPath(grnaDto.getProgrammeId(), file);
//
//        String gbffFilePath =gbffPath;
//        String configureFilePath = upload(grnaDto.getConfigureFile());
//        String outFilePath = getPath();
//        String cofigFilePath = getPath() +"gRNA.conf";
//
//        outFilePath = gRNASetCofig(gbffFilePath,configureFilePath,outFilePath,cofigFilePath, grnaDto.getProgrammeId() ,grnaDto);
//        String predictionPath = "D:\\fenzhifangan\\gRNA_Prediction_v20220728\\bin\\gRNA_Prediction.exe -c "+cofigFilePath;
////        CmdUtil.execCmdOrder(predictionPath);
//        CmdUtil.callCmd(predictionPath);
//
//        FileTable zipfile  =new FileTable();
//        zipfile.setId( IdUtil.getSnowflakeNextIdStr());
//        String zipPath = CmdUtil.compressGrna(cofigFilePath,outFilePath,getPath(),zipfile.getId() + "gRNA");
//
//        zipfile.setFile_url(zipPath);
//        zipfile.setFile_name(getFileName(getGeneName(zipPath)));
//        zipfile.setFile_source(4);
//        fileUploadService.saveFileInfo(zipfile);
//
//        Hostory hostory =new Hostory();
//        hostory.setId(IdUtil.getSnowflakeNextIdStr());
//        hostory.setMolecularScheme(zipfile.getId());
//        hostory.setProgrammeId(grnaDto.getProgrammeId());
//        hostory.setCreateTime(new Date());
//        hostory.setCreateStaffNo(SecurityUtils.getUserId());
//        hostory.setHistoryStep(grnaDto.getHistoryStep());
//        hostory.setHistoryType("5");
//        historyService.save(hostory);
//
//        return  closing(configureFilePath,cofigFilePath,gbffFilePath);
//    }
//
//    @PostMapping("/primerPredictionFromGenBank")
//    public AjaxResult primerPredictionFromGenBank(PrimerPredictionFromGenBankDto primerPredictionFromGenBankDto) throws IOException, InterruptedException {
//        String cmd = "D:\\fenzhifangan\\Primer_Prediction_From_GenBank_version_20220408\\GUI\\Primer_Prediction_From_GenBank_v3.exe";
//        QueryWrapper programmeWrapper = new QueryWrapper();
//        programmeWrapper.eq("id", primerPredictionFromGenBankDto.getProgrammeId());// 未打包标识
//        Programme programme =iProgrammeService.getOne(programmeWrapper);
//
//        QueryWrapper fileWrapper = new QueryWrapper();
//        fileWrapper.eq("id", programme.getLocalFileId()); // 未打包标识
//        cn.siat.gene.file.entity.File file =iFileService.getOne(fileWrapper);
//        String genbank = gbffUtil.getGbffPath(primerPredictionFromGenBankDto.getProgrammeId(), file);
//        String conf =upload(primerPredictionFromGenBankDto.getConfigureFile());
//        String vector = upload(primerPredictionFromGenBankDto.getVector());
//        String primer3 = "D:\\fenzhifangan\\Primer_Prediction_From_GenBank_version_20220408\\GUI\\primer3_core.exe";
//        String outdir =  getPath()+"\\"+ DateTime.now().toString("yyyy-MM-dd") + primerPredictionFromGenBankDto.getProgrammeId()+"\\";
//        File file1 = new File(outdir);
//
//        if (file1.mkdirs()) {
//
//        }
//        cmd =cmd+" -genbank="+genbank;
//        cmd =cmd+" -conf="+conf;
//        cmd =cmd+" -insert_site="+primerPredictionFromGenBankDto.getInsert_site();
//        cmd =cmd+" -width="+primerPredictionFromGenBankDto.getWidth();
//        cmd =cmd+" -overlap="+primerPredictionFromGenBankDto.getOverlap();
//        cmd =cmd+" -arm="+primerPredictionFromGenBankDto.getArm();
//        cmd =cmd+" -left="+primerPredictionFromGenBankDto.getLeft();
//        cmd =cmd+" -right="+primerPredictionFromGenBankDto.getRight();
//        cmd =cmd+" -min_primer="+primerPredictionFromGenBankDto.getMin_primer();
//        cmd =cmd+" -max_primer="+primerPredictionFromGenBankDto.getMax_primer();
//        cmd =cmd+" -opt_primer="+primerPredictionFromGenBankDto.getOpt_primer();
//        cmd =cmd+" -diff_tm="+primerPredictionFromGenBankDto.getDiff_tm();
//        cmd =cmd+" -varmr="+primerPredictionFromGenBankDto.getVarmr();
//        cmd =cmd+" -varml="+primerPredictionFromGenBankDto.getVarml();
//        cmd =cmd+" -vector="+vector;
//        cmd =cmd+" -primer3="+primer3;
//        cmd =cmd+" -outdir="+outdir;
//
//
//
//        CmdUtil.execute(cmd);
//        FileTable zipfile  =new FileTable();
//        zipfile.setId( IdUtil.getSnowflakeNextIdStr());
//        String zipPath = CmdUtil.compressGrna("cofigFilePath",outdir,getPath(),zipfile.getId() + "Primer_Prediction_From_GenBank");
//        return  closingPrimerPredictionFromGenBank(conf,vector,genbank);
//    }
//    public AjaxResult  closingPrimerPredictionFromGenBank(String conf,String vector,String genbank){
//        System.out.print("删除配置文件");
//        GbffUtil.deleteFile(conf);
//        System.out.print("删除vector文件");
//        GbffUtil.deleteFile(vector);
//        System.out.print("删除gbff文件");
//        GbffUtil.deleteFile(genbank);
//        return AjaxResult.success();
//    }
//
//    @PostMapping("/geneKnockOut")
//    public AjaxResult geneKnockOut(GeneKnockOutDto geneKnockOutDto) throws IOException, InterruptedException {
//        QueryWrapper programmeWrapper = new QueryWrapper();
//        programmeWrapper.eq("id", geneKnockOutDto.getProgrammeId());// 未打包标识
//        Programme programme =iProgrammeService.getOne(programmeWrapper);
//
//        QueryWrapper fileWrapper = new QueryWrapper();
//        fileWrapper.eq("id", programme.getLocalFileId()); // 未打包标识
//        cn.siat.gene.file.entity.File file =iFileService.getOne(fileWrapper);
//        String gbffPath = gbffUtil.getGbffPath(geneKnockOutDto.getProgrammeId(), file);
//
//        String gbffFilePath =gbffPath;
//        String configureFilePath = upload(geneKnockOutDto.getConfigureFile());
//        String vectorPath = upload(geneKnockOutDto.getVector());
//        String kanMXPath = upload(geneKnockOutDto.getKanMX());
//        String outFilePath = getPath();
//        String cofigFilePath = getPath() +"knockOut.conf";
//        String binPath ="D:\\fenzhifangan\\Gene_Knockout_Beta_Kan\\bin\\Predicting_Primer.exe";
//        outFilePath = geneKnockOutSetCofig(binPath,gbffFilePath,configureFilePath,vectorPath,kanMXPath,outFilePath,cofigFilePath, geneKnockOutDto.getProgrammeId(),geneKnockOutDto);
//        String predictionPath = "D:\\fenzhifangan\\Gene_Knockout_Beta_Kan\\bin\\Gene_Knockout.exe -c "+cofigFilePath;
//        CmdUtil.callCmd(predictionPath);
//
//        FileTable zipfile  =new FileTable();
//        zipfile.setId( IdUtil.getSnowflakeNextIdStr());
//        String zipPath = CmdUtil.compressGrna(cofigFilePath,outFilePath,getPath(),zipfile.getId() + "geneKnockOut");
//
//        zipfile.setFile_url(zipPath);
//        zipfile.setFile_name(getFileName(getGeneName(zipPath)));
//        zipfile.setFile_source(4);
//        fileUploadService.saveFileInfo(zipfile);
//
//        Hostory hostory =new Hostory();
//        hostory.setId(IdUtil.getSnowflakeNextIdStr());
//        hostory.setMolecularScheme(zipfile.getId());
//        hostory.setProgrammeId(geneKnockOutDto.getProgrammeId());
//        hostory.setCreateTime(new Date());
//        hostory.setCreateStaffNo(SecurityUtils.getUserId());
//        hostory.setHistoryStep(geneKnockOutDto.getHistoryStep());
//        hostory.setHistoryType("5");
//        historyService.save(hostory);
//
//        return  closingGeneKnockOut(configureFilePath,cofigFilePath,gbffFilePath,kanMXPath,vectorPath);
//    }
//
//
//    public String getGeneName(String path){
//        return path.substring(path.lastIndexOf("/")+1);
//    }
//    public AjaxResult closing(String configureFilePath,String cofigFilePath,String gbffPath){
//        System.out.print("删除配置文件");
//        GbffUtil.deleteFile(configureFilePath);
//        System.out.print("删除config文件");
//        GbffUtil.deleteFile(cofigFilePath);
//        System.out.print("删除gbff文件");
//        GbffUtil.deleteFile(gbffPath);
//        return AjaxResult.success();
//    }
//
//    public AjaxResult closingGeneKnockOut(String configureFilePath,String cofigFilePath,String gbffPath,String kanMXPath,String vectorPath){
//        System.out.print("删除配置文件");
//        GbffUtil.deleteFile(configureFilePath);
//        System.out.print("删除config文件");
//        GbffUtil.deleteFile(cofigFilePath);
//        System.out.print("删除gbff文件");
//        GbffUtil.deleteFile(gbffPath);
//        System.out.print("删除kanMX文件");
//        GbffUtil.deleteFile(kanMXPath);
//        System.out.print("删除vector文件");
//        GbffUtil.deleteFile(vectorPath);
//        return AjaxResult.success();
//    }
//
//    public String geneKnockOutSetCofig(String binPath,String gbffFilePath, String configureFilePath,String vectorPath,String kanMXPath,String outFilePath,String cofigFilePath, String programmeId,GeneKnockOutDto geneKnockOutDto) throws IOException {
//        System.out.println("开始解析"+new Date());
//        StringBuilder sb = new StringBuilder();
//        sb.append("[P1]"+"\n");
//        sb.append("primer3_bin="+binPath+"\n");
//        sb.append("outdir="+outFilePath+"\\"+ DateTime.now().toString("yyyy-MM-dd") + programmeId +"\\"+"\n");
//        String outdir = outFilePath+"\\"+ DateTime.now().toString("yyyy-MM-dd") + programmeId+"\\";
//        sb.append("genome="+gbffFilePath+"\n");
//        sb.append("vector="+vectorPath+"\n");
//        sb.append("kanmx="+kanMXPath+"\n");
//        sb.append("knockout_conf="+configureFilePath+"\n");
//        sb.append("left_flank="+geneKnockOutDto.getLeft_flank()+"\n");
//        sb.append("right_flank="+geneKnockOutDto.getRight_flank()+"\n");
//        sb.append("extend_size="+geneKnockOutDto.getExtend_size()+"\n");
//        sb.append("len_overhang="+geneKnockOutDto.getLen_overhang()+"\n");
//        sb.append("[P2]"+"\n");
//        sb.append("max_num="+geneKnockOutDto.getMax_num()+"\n");
//        sb.append("min_pt="+geneKnockOutDto.getMin_pt()+"\n");
//        sb.append("max_pt="+geneKnockOutDto.getMax_pt()+"\n");
//        sb.append("opt_pt="+geneKnockOutDto.getOpt_pt()+"\n");
//        sb.append("min_gc="+geneKnockOutDto.getMin_gc()+"\n");
//        sb.append("max_gc="+geneKnockOutDto.getMax_gc()+"\n");
//        sb.append("opt_gc="+geneKnockOutDto.getOpt_gc()+"\n");
//        sb.append("min_tm="+geneKnockOutDto.getMin_tm()+"\n");
//        sb.append("max_tm="+geneKnockOutDto.getMax_tm()+"\n");
//        sb.append("opt_tm="+geneKnockOutDto.getOpt_tm()+"\n");
//        sb.append("diff_tm="+geneKnockOutDto.getDiff_tm()+"\n");
//        sb.append("max_poly="+geneKnockOutDto.getMax_poly()+"\n");
//        sb.append("left_start="+geneKnockOutDto.getLeft_start()+"\n");
//        sb.append("right_start="+geneKnockOutDto.getRight_start()+"\n");
//        sb.append("left_pt="+geneKnockOutDto.getLeft_pt()+"\n");
//        sb.append("right_pt="+geneKnockOutDto.getRight_pt()+"\n");
//        sb.append("window="+geneKnockOutDto.getWindow()+"\n");
//        saveFile(sb.toString(),cofigFilePath);
//        return outdir;
//    }
//    public String gRNASetCofig(String gbffFilePath, String configureFilePath,String outFilePath,String cofigFilePath, String programmeId,GRNADto grnaDto) throws IOException {
//        System.out.println("开始解析"+new Date());
//        StringBuilder sb = new StringBuilder();
//        sb.append("[P1]"+"\n");
//
//        String outdir = outFilePath+"\\"+ DateTime.now().toString("yyyy-MM-dd") + programmeId+"\\";
//        sb.append("outdir="+outFilePath+"\\"+ DateTime.now().toString("yyyy-MM-dd") + programmeId +"\\"+"\n");
//        sb.append("genome="+gbffFilePath+"\n");
//        sb.append("gene_conf="+configureFilePath+"\n");
//
//        sb.append("[P2]"+"\n");
//        sb.append("gRNA_type="+grnaDto.getGRNA_type()+"\n");
//        sb.append("gene_upstream_len="+grnaDto.getGene_upstream_len()+"\n");
//        sb.append("gene_downstream_len="+grnaDto.getGene_downstream_len()+"\n");
//        sb.append("enzyme_name="+grnaDto.getEnzyme_name()+"\n");
//        sb.append("enzyme_site="+grnaDto.getEnzyme_site()+"\n");
//        sb.append("forward_overhang="+grnaDto.getForward_overhang()+"\n");
//        sb.append("reverse_overhang="+grnaDto.getReverse_overhang()+"\n");
//
//        sb.append("[P3]"+"\n");
//        sb.append("design_type="+grnaDto.getDesign_type()+"\n");
//        sb.append("model="+grnaDto.getModel()+"\n");
//        sb.append("score_gc="+grnaDto.getScore_gc()+"\n");
//        sb.append("scoringMethod="+grnaDto.getScoringMethod()+"\n");
//        sb.append("target_type="+grnaDto.getTarget_type()+"\n");
//        sb.append("guid_size="+grnaDto.getGuid_size()+"\n");
//        sb.append("pam="+grnaDto.getPam()+"\n");
//        sb.append("max_oftargets="+grnaDto.getMax_oftargets()+"\n");
//        sb.append("max_mismatches="+grnaDto.getMax_mismatches()+"\n");
//        sb.append("grna_num="+grnaDto.getGrna_num()+"\n");
//        sb.append("tale_min="+grnaDto.getTale_min()+"\n");
//        sb.append("tale_max="+grnaDto.getTale_max()+"\n");
//
//        saveFile(sb.toString(),cofigFilePath);
//          return outdir;
//    }
//
//
//
//    private void saveFile(String sb,String cofigFilePath) throws IOException {
//        File file = new File(cofigFilePath);
//        if(!file.exists()){
//            file.getParentFile().mkdirs();
//        }
//        file.createNewFile();
//        FileWriter fw = new FileWriter(file, true);
//        BufferedWriter bw = new BufferedWriter(fw);
//        bw.write(sb);
//        bw.flush();
//        bw.close();
//        fw.close();
//    }
//
//    /**
//     * 文件上传
//     */
//    public String upload(MultipartFile file) throws IOException {
//        System.out.println("开始上传"+new Date());
//        String fileName = getFileName(file.getOriginalFilename());
//
//
//
//
//        File saveFile=new File(getPath()+fileName);
//        if(!saveFile.getParentFile().exists()){
//            saveFile.getParentFile().mkdirs();
//        }
//        file.transferTo(saveFile);
//        System.out.println("结束上传"+new Date());
//        return saveFile.getPath();
//    }
//
//    public String getFileName(String originName){
//        return originName.substring(originName.lastIndexOf("/")+1);
//    }
//
//    public String getPath(){
//        // 获取当前操作系统
//        String osName = System.getProperties().get("os.name").toString().toLowerCase(Locale.ROOT);
//        String path="";
//        if(osName.startsWith("win")){
//            path="D:\\Test\\"+ DateTime.now().toString("yyyy-MM-dd");
//        }else{
//            path="/genefile/"+ DateTime.now().toString("yyyy-MM-dd")+"/";
//        }
//        return path;
//    }
//
//    @GetMapping("/download")
//    public void downloadFile(String FileId, HttpServletRequest request, HttpServletResponse response){
//        QueryWrapper fileWrapper = new QueryWrapper();
//        fileWrapper.eq("id",FileId); // 未打包标识
//        cn.siat.gene.file.entity.File downloadfile =iFileService.getOne(fileWrapper);
//        BufferedInputStream bis = null;
//        try {
//            File file = new File(downloadfile.getFileUrl());
//            if (file.exists()) {
//                long p = 0L;
//                long toLength = 0L;
//                long contentLength = 0L;
//                int rangeSwitch = 0;
//                long fileLength;
//                String rangBytes = "";
//                fileLength = file.length();
//
//                // get file content
//                InputStream ins = new FileInputStream(file);
//                bis = new BufferedInputStream(ins);
//
//                // tell the client to allow accept-ranges
//                response.reset();
//                response.setHeader("Accept-Ranges", "bytes");
//
//                // client requests a file block download start byte
//                String range = request.getHeader("Range");
//                if (range != null && range.trim().length() > 0 && !"null".equals(range)) {
//                    response.setStatus(javax.servlet.http.HttpServletResponse.SC_PARTIAL_CONTENT);
//                    rangBytes = range.replaceAll("bytes=", "");
//                    if (rangBytes.endsWith("-")) { // bytes=270000-
//                        rangeSwitch = 1;
//                        p = Long.parseLong(rangBytes.substring(0, rangBytes.indexOf("-")));
//                        contentLength = fileLength - p; // 客户端请求的是270000之后的字节（包括bytes下标索引为270000的字节）
//                    } else { // bytes=270000-320000
//                        rangeSwitch = 2;
//                        String temp1 = rangBytes.substring(0, rangBytes.indexOf("-"));
//                        String temp2 = rangBytes.substring(rangBytes.indexOf("-") + 1, rangBytes.length());
//                        p = Long.parseLong(temp1);
//                        toLength = Long.parseLong(temp2);
//                        contentLength = toLength - p + 1; // 客户端请求的是 270000-320000 之间的字节
//                    }
//                } else {
//                    contentLength = fileLength;
//                }
//
//                // 如果设设置了Content-Length，则客户端会自动进行多线程下载。如果不希望支持多线程，则不要设置这个参数。
//                // Content-Length: [文件的总大小] - [客户端请求的下载的文件块的开始字节]
//                response.setHeader("Content-Length", new Long(contentLength).toString());
//
//                // 断点开始
//                // 响应的格式是:
//                // Content-Range: bytes [文件块的开始字节]-[文件的总大小 - 1]/[文件的总大小]
//                if (rangeSwitch == 1) {
//                    String contentRange = new StringBuffer("bytes ").append(new Long(p).toString()).append("-")
//                            .append(new Long(fileLength - 1).toString()).append("/")
//                            .append(new Long(fileLength).toString()).toString();
//                    response.setHeader("Content-Range", contentRange);
//                    bis.skip(p);
//                } else if (rangeSwitch == 2) {
//                    String contentRange = range.replace("=", " ") + "/" + new Long(fileLength).toString();
//                    response.setHeader("Content-Range", contentRange);
//                    bis.skip(p);
//                } else {
//                    String contentRange = new StringBuffer("bytes ").append("0-").append(fileLength - 1).append("/")
//                            .append(fileLength).toString();
//                    response.setHeader("Content-Range", contentRange);
//                }
//
//                String fileName = file.getName();
//                response.setContentType("application/octet-stream");
//                response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
//
//                OutputStream out = response.getOutputStream();
//                int n = 0;
//                long readLength = 0;
//                int bsize = 1024;
//                byte[] bytes = new byte[bsize];
//                if (rangeSwitch == 2) {
//                    // 针对 bytes=27000-39000 的请求，从27000开始写数据
//                    while (readLength <= contentLength - bsize) {
//                        n = bis.read(bytes);
//                        readLength += n;
//                        out.write(bytes, 0, n);
//                    }
//                    if (readLength <= contentLength) {
//                        n = bis.read(bytes, 0, (int) (contentLength - readLength));
//                        out.write(bytes, 0, n);
//                    }
//                } else {
//                    while ((n = bis.read(bytes)) != -1) {
//                        out.write(bytes, 0, n);
//                    }
//                }
//                out.flush();
//                out.close();
//                bis.close();
//
//            }
//        } catch (IOException ie) {
//
//        } catch (Exception e) {
//            log.error(e.getMessage());
//        }
//    }
//}
